package 优先算法.递归_搜索与回溯.二叉树深度搜索.计算布尔二叉树的值;

/**
 * https://leetcode.cn/problems/evaluate-boolean-binary-tree/submissions/561576169/
 */
public class Main {

}
class Solution {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public boolean evaluateTree(TreeNode root) {
        if(root.left == null){
            if(root.val == 0){
                return false;
            }else{
                return true;
            }
        }
        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);
        boolean ret;
        if(root.val == 2){
            // 逻辑||
             ret= left || right;
        }else{
             ret = left && right;
        }
        return ret;
    }
}